const api = require("../../../utils/api")
const getwxphone = require("../../../utils/getwxphone")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    index: 0,
    index2: 0,
    index3: 0,
    dishi: ['----请选择招考地市----'],
    nsh: ['----请选择招考农商行----'],
    phone: 0,
    theList: ''
  },


  dishiChange: function (e) {
    let num = e.detail.value;
    let that = this;
    console.log('dishi发送选择改变，携带值为', that.data.dishi[num]);
    this.setData({
      index: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=52256&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'dishi',
        grtext: that.data.dishi[num]
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].nsh)
        }
        that.setData({
          nsh: list
        });
      }
    })
  },
  nshChange: function (e) {
    var that = this;
    console.log('nsh发送选择改变，携带值为', that.data.nsh[e.detail.value])
    this.setData({
      index2: e.detail.value
    })
  },

  onLoad: function (options) {
    var that = this;
    api.load(options)
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=52256&callback=?', //接收url
      data: {
        level: '1',
        dishi: ''
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        list.push('----请选择报考地市----')
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].dishi)
        }
        that.setData({
          dishi: list
        });
      }
    })


  },

  getPhoneNumber(e) {
    var _ = this;
    const info = {
      area: wx.getStorageSync('area'),
      agent: wx.getStorageSync('agent'),
      page: wx.getStorageSync('page'),
      activeId: 21
    }

    getwxphone(e.detail.code, 52256, 'chaxun', info)
      .then(res => {
        console.log(res);
        this.gosearch()
        
      })
      .catch(err => {
        console.log(err);
      })
  },
  gosearch(e) {
    var that = this;
    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=52256&callback=?",
      data: {
        dishi: that.data.dishi[that.data.index],
        nsh: that.data.nsh[that.data.index2],
        limits: '100'
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson)
        if (theJson.status === 1) {
          that.setData({
            theList: theJson.lists
          })
          wx.pageScrollTo({
            scrollTop:1500,
            duration: 1500,
          })
          console.log(that.data.theList)
        } else {
          wx.showToast({
            title: '暂无数据！',
          })
        }

      }
    })
  },
  tijiao: function () {
    var that = this;
    var dishi = that.data.dishi[that.data.index];
    var nsh = that.data.nsh[that.data.index2];
    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=52256&callback=?",
      data: {
        dishi: dishi,
        nsh: nsh,
        limits: '100'
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson)
        if (theJson.status === 1) {
          that.setData({
            theList: theJson.lists
          })
          wx.pageScrollTo({
            scrollTop:1500,
            duration: 1500,
          })
          console.log(that.data.theList)
        } else {
          wx.showToast({
            title: '暂无数据！',
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onshow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onshareAppMessage: function () {
    var that = this;
    return {
      title: '2023山东农商行面试考情查询',
      path: 'pages/nsh/mskq/mskq?area=' + that.data.area + '&agent=' + that.data.agent + '&page=' + that.data.page
    }
  },
  /**分享到朋友圈*/
  onshareTimeline: function () {
    var that = this;
    return {
      title: '2023山东农商行面试考情查询',
      path: 'pages/nsh/mskq/mskq?area=' + that.data.area + '&agent=' + that.data.agent + '&page=' + that.data.page
    }
  }
})